package registnet.base;

import java.util.List;
import java.util.ListIterator;
import java.util.Vector;

/**
 * This class provides default implementations for the <code>IPlanOfCourseWork</code> interface.
 */
public abstract class AbstractPlanOfCourseWork implements IPlanOfCourseWork {

	/**
	 * The student number of the student associated with the plan of coursework.
	 */
	protected String studentNumber;
	
	/**
	 * The student number of the student associated with the plan of coursework.
	 */
	protected ICurriculum curriculum;
	
	/**
	 * The list of courses associated with the plan of coursework.
	 */
	protected List<ICourse> courses;
	
	@Override
	public void addCourse(ICourse course) {
		courses.add(course);
	}
	
	@Override
	public boolean contains(ICourse course) {
		ListIterator<ICourse> li = courses.listIterator();
		while(li.hasNext())
			if(course.getCourseCode().equals(li.next().getCourseCode()))
				return true;
		return false;
	}
	
	@Override
	public boolean contains(String courseCode) {
		ListIterator<ICourse> li = courses.listIterator();
		while(li.hasNext())
			if(courseCode.equals(li.next().getCourseCode()))
				return true;
		return false;
	}
	
	@Override
	public List<ICourse> getAllCourses() {
		return courses;
	}
	
	@Override
	public ICourse getCourse(String courseCode) {
		ListIterator<ICourse> li = courses.listIterator();
		while(li.hasNext()){
			ICourse tmpCourse = li.next();
			if(courseCode.equals(tmpCourse.getCourseCode()))
				return tmpCourse;
		}
		return null;
	}
	
	@Override
	public List<ICourse> getCourses(int year, int semester) {
		List<ICourse> retval = new Vector<ICourse>();
		ListIterator<ICourse> li = courses.listIterator();
		while(li.hasNext()){
			ICourse tmpCourse = li.next();
			if(year==tmpCourse.getYear() && semester==tmpCourse.getSemester())
				retval.add(tmpCourse);
		}
		return retval;
	}
	
	@Override
	public List<ICourse> getCourses(int year) {
		List<ICourse> retval = new Vector<ICourse>();
		ListIterator<ICourse> li = courses.listIterator();
		while(li.hasNext()){
			ICourse tmpCourse = li.next();
			if(year==tmpCourse.getYear())
				retval.add(tmpCourse);
		}
		return retval;
	}
	
	@Override
	public List<ICourse> getCourses(String type) {
		List<ICourse> retval = new Vector<ICourse>();
		ListIterator<ICourse> li = courses.listIterator();
		while(li.hasNext()){
			CourseWork tmpCourse = (CourseWork)li.next();
			if(type.equals(tmpCourse.getType()))
				retval.add(tmpCourse);
		}
		return retval;
	}
	
	@Override
	public ICurriculum getCurriculum() {
		return curriculum;
	}
	
	@Override
	public List<ICourse> getGECourses(String rgepDomain) {
		List<ICourse> retval = new Vector<ICourse>();
		ListIterator<ICourse> li = courses.listIterator();
		while(li.hasNext()){
			CourseWork tmpCourse = (CourseWork)li.next();
			if(tmpCourse.getType().equals("GE("+rgepDomain+")"))
				retval.add(tmpCourse);
		}
		return retval;
	}
	
	@Override
	public List<ICourse> getGECourses(String rgepDomain, int year, int semester) {
		List<ICourse> retval = new Vector<ICourse>();
		ListIterator<ICourse> li = courses.listIterator();
		while(li.hasNext()){
			CourseWork tmpCourse = (CourseWork)li.next();
			if(tmpCourse.getType().equals("GE("+rgepDomain+")") && tmpCourse.getYear()==year && tmpCourse.getSemester()==semester)
				retval.add(tmpCourse);
		}
		return retval;
	}
	
	@Override
	public List<ICourse> getCourses(String type, int year, int semester) {
		List<ICourse> retval = new Vector<ICourse>();
		ListIterator<ICourse> li = courses.listIterator();
		while(li.hasNext()){
			CourseWork tmpCourse = (CourseWork)li.next();
			if(tmpCourse.getType().equals(type) && tmpCourse.getYear()==year && tmpCourse.getSemester()==semester)
				retval.add(tmpCourse);
		}
		return retval;
	}

	@Override
	public String getStudentNumber() {
		return studentNumber;
	}
	
	@Override
	public void setCurriculum(ICurriculum curriculum) {
		this.curriculum = curriculum;
		
	}
	
	@Override
	public void setStudentNumber(String studentNumber) {
		this.studentNumber = studentNumber;
	}

}
